﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace dahtd4ever
{
    public class Keyboard
    {

        public KeyboardState CurrentKeyboardState;
        public GamePadState CurrentGamePadState;

        public KeyboardState LastKeyboardState;
        public GamePadState LastGamePadState;

        public Keyboard()
        {

        }
        public bool Quit
        {
            get
            {
                return (IsNewKeyPress(Keys.Escape) && (ScreenManager.gameState == GameState.Menu));
            }
        }
        public bool MenuUp
        {
            get
            {
                return IsNewKeyPress(Keys.Up);
            }
        }
        public bool MenuDown
        {
            get
            {
                return IsNewKeyPress(Keys.Down);
            }
        }
        public bool MenuSelect
        {
            get
            {
                return IsNewKeyPress(Keys.Enter);
            }
        }
        public bool hit
        {
            get
            {
                return IsNewKeyPress(Keys.Space);
            }
        }
        public bool MenuBack
        {
            get
            {
                return (IsNewKeyPress(Keys.Back) && (ScreenManager.gameState == GameState.Menu));
            }
        }

        /// <summary>
        /// /////////////////////////////////////////
        /// PLAYER 1
        /// </summary>
        public bool MoveUp1
        {
            get
            {
                return IsPressedKey(Keys.Up) && (ScreenManager.gameState == GameState.Play);
            }
        }
        public bool MoveLeft1
        {
            get
            {
                return IsPressedKey(Keys.Left) && (ScreenManager.gameState == GameState.Play);
            }
        }
        public bool MoveRight1
        {
            get
            {
                return IsPressedKey(Keys.Right) && (ScreenManager.gameState == GameState.Play);
            }
        }
        public bool MoveDown1
        {
            get
            {
                return IsPressedKey(Keys.Down) && (ScreenManager.gameState == GameState.Play);
            }
        }

        /// <summary>
        /// /////////////////////////////////////////
        /// PLAYER 2
        /// </summary>
        public bool MoveUp2
        {
            get
            {
                return IsPressedKey(Keys.W) && (ScreenManager.gameState == GameState.Play);
            }
        }
        public bool MoveLeft2
        {
            get
            {
                return IsPressedKey(Keys.A) && (ScreenManager.gameState == GameState.Play);
            }
        }
        public bool MoveRight2
        {
            get
            {
                return IsPressedKey(Keys.D) && (ScreenManager.gameState == GameState.Play);
            }
        }
        public bool MoveDown2
        {
            get
            {
                return IsPressedKey(Keys.S) && (ScreenManager.gameState == GameState.Play);
            }
        }

        public bool Pause
        {
            get
            {
                return IsNewKeyPress(Keys.Escape) && (ScreenManager.gameState == GameState.Play);
            }
        }
        public void Update()
        {
            LastKeyboardState = CurrentKeyboardState;
            LastGamePadState = CurrentGamePadState;

            CurrentKeyboardState = Microsoft.Xna.Framework.Input.Keyboard.GetState();
            CurrentGamePadState = Microsoft.Xna.Framework.Input.GamePad.GetState(PlayerIndex.One);
        }
        public bool IsNewKeyPress(Keys key)
        {
            return (CurrentKeyboardState.IsKeyDown(key) &&
                    LastKeyboardState.IsKeyUp(key));
        }
        public bool IsPressedKey(Keys key)
        {
            if (CurrentKeyboardState.IsKeyDown(key))
            {
                return true;
            }
            else
                return false;
        }
    }
}
